Skip to content

Give each reference to a repeated footnote its own id - #777

Open
SwastikTripathi wants to merge 2 commits into
trentm:masterfrom
SwastikTripathi:fix/footnote-ref-unique-ids
Open

SwastikTripathi wants to merge 2 commits into
trentm:masterfrom
SwastikTripathi:fix/footnote-ref-unique-ids

Conversation

@SwastikTripathi

Copy link
Copy Markdown
Contributor

When a footnote is referenced more than once, every reference gets the same id="fnref-<id>", so the page has duplicate ids. That's invalid HTML, and anything that links to or styles a single reference (the footnote's back link included) only sees whichever one the browser picks:

markdown2.markdown("x[^1] y[^1]\n\n[^1]: note\n", extras=["footnotes"])
# <sup class="footnote-ref" id="fnref-1">... <sup class="footnote-ref" id="fnref-1">...

The first reference in the document now keeps fnref-<id>, which the back link points to, and later ones get fnref2-<id>, fnref3-<id> and so on. A normalized footnote id only contains word characters and -, so these can't collide with another footnote's fnref-<id>.

The ids are numbered in the same pass that already numbers the references (_do_footnote_marker), not while the links are processed. That pass runs over the finished text in document order, while lists are rendered before the paragraphs around them, so counting earlier would give fnref-<id> to a reference in a list instead of the first one in the text.

repeated_footnote_labels (from #727) already covers repeated references in paragraphs, list items and footnote bodies. Its expected output had the duplicate ids, so I updated it. It fails before the change and passes after. The rest of the suite is unchanged (the same 14 known failures as on master).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant